public class LeetCOde {
    public static  String multiply(String num1, String num2) {
        int n =num1.length()+num2.length()-1;
        int[] tmp = new int[n];
        StringBuilder s1 = new StringBuilder(num1);
        StringBuilder s2 = new StringBuilder(num2);
        s1.reverse();
        s2.reverse();
        for (int i = 0; i < num1.length(); i++) {
            for (int j = 0; j < num2.length(); j++) {
                tmp[i+j] +=  (s1.charAt(i)-'0')*(s2.charAt(j)-'0');
            }
        }
        StringBuilder ret = new StringBuilder();
        int i = 0,t = 0;
        while(i<n||t!=0){
            if(i<n){
                t+=tmp[i++];
            }
            ret.append((char)(t%10+'0'));
            t/=10;
        }
        while(ret.length()>1 && ret.charAt(ret.length()-1)=='0'){
            ret.deleteCharAt((ret.length()-1));
        }
        return ret.reverse().toString();
    }

    public static void main(String[] args) {
        String a = "123";
        String b = "456";
        String c = multiply(a,b);
    }
}
